{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 1. Stick Person" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**New Processing functions**:\n", "\n", "* stroke(GRAYSCALE) - sets the color of lines and borders around shapes\n", " * stroke(RED, GREEN, BLUE)\n", " * stroke(RED, GREEN, BLUE, ALPHA)\n", "* noStroke() - no drawing of the border\n", "\n", "**New ideas**:\n", "\n", "* variable - a named value\n", "* type - the type of the value\n", " * int - integer, whole number, positive or negative\n", " * float - a floating-point number (number with a dot in it), positive or negative\n", " * void - no type, the null type\n", "* defining functions - create a new function\n", "\n", "**New Jargon**:\n", "\n", "* variable\n", "* function\n", "* type\n", "* declare, or declaration\n", "* assign, or assignment\n", "* parameter - a special variable, see below\n", "* `call` a function" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.1 Variables" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```\n", "TYPE NAME;\n", "TYPE NAME = INITIAL_VALUE;\n", "```\n", "\n", "* Declare\n", "* Declare and Assign" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 1.1.1 Examples:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```java\n", "int weight = 120;\n", "int age = 19;\n", "float height = 152.4; \n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 1.1.2 Variable Name Conventions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* always start with lowercase letter\n", "* unless it is a CONSTANT, and then use all uppercase letters\n", " * `float GRAVITY = 9.8;`\n", "* variables that are composed of multiple words should use camelCase or use underscores_to_separate\n", " * `int theDogThatBarkedInTheNight = 3;`\n", " * `int the_dog_that_barked_in_the_night = 3;`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 1.1.3 Why Variables?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's see an example!\n", "\n", "Let's draw a stick person at location (200, 100):" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.2 Plain Drawing" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**NOTE**: separated the numbers that indicate where (x, y) from size" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "application/javascript": [ "\n", " var component = document.getElementById(\"sketch_13\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"state_13\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"controls_div_13\");\n", " if (component != undefined)\n", " component.remove();\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " // FIXME: Stop all previously running versions (?)\n", " var processingInstance = Processing.getInstanceById(\"canvas_13\");\n", " if (processingInstance != undefined && processingInstance.isRunning())\n", " processingInstance.noLoop();\n", " });\n", "\n", "\n", " var output_area = this;\n", " // find my cell element\n", " var cell_element = output_area.element.parents('.cell');\n", " // which cell is it?\n", " var cell_idx = Jupyter.notebook.get_cell_elements().index(cell_element);\n", " // get the cell object\n", " var cell = Jupyter.notebook.get_cell(cell_idx);\n", "\n", " function jyp_print(cell, newline) {\n", " return function(message) {\n", " cell.get_callbacks().iopub.output({header: {\"msg_type\": \"stream\"},\n", " content: {text: message + newline,\n", " name: \"stdout\"}});\n", " }\n", " }\n", " window.jyp_println = jyp_print(cell, \"\\n\");\n", " window.jyp_print = jyp_print(cell, \"\");\n", "\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " Processing.logger.println = jyp_print(cell, \"\\n\");\n", " Processing.logger.print = jyp_print(cell, \"\");\n", " });\n", "\n", "\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " Sketch #13:
\n", "
\n", "
\n", "
\n", " \n", " \n", " \n", " \n", "
\n", "Sketch #13 state: Loading...
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "size(400, 300);\n", "\n", "// Shadow:\n", "fill(180);\n", "noStroke();\n", "ellipse(200, 100 + 100, 30, 10);\n", "\n", "// body and the rest\n", "fill(255);\n", "stroke(0);\n", "// body:\n", "line(200, 100, 200, 100 + 100); // x, y, \n", "// head:\n", "ellipse(200, 100, 100, 100); // (x, y, w, h)\n", "// arms:\n", "line(200 - 50, 100 + 60, \n", " 200 + 50, 100 + 60);\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, consider what you would need to do to:\n", "\n", "* move the stick person to a different location\n", "* make it taller or shorter" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.3 Half as Tall" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "application/javascript": [ "\n", " var component = document.getElementById(\"sketch_1\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"state_1\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"controls_div_1\");\n", " if (component != undefined)\n", " component.remove();\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " // FIXME: Stop all previously running versions (?)\n", " var processingInstance = Processing.getInstanceById(\"canvas_1\");\n", " if (processingInstance != undefined && processingInstance.isRunning())\n", " processingInstance.noLoop();\n", " });\n", "\n", "\n", " var output_area = this;\n", " // find my cell element\n", " var cell_element = output_area.element.parents('.cell');\n", " // which cell is it?\n", " var cell_idx = Jupyter.notebook.get_cell_elements().index(cell_element);\n", " // get the cell object\n", " var cell = Jupyter.notebook.get_cell(cell_idx);\n", "\n", " function jyp_print(cell, newline) {\n", " return function(message) {\n", " cell.get_callbacks().iopub.output({header: {\"msg_type\": \"stream\"},\n", " content: {text: message + newline,\n", " name: \"stdout\"}});\n", " }\n", " }\n", " window.jyp_println = jyp_print(cell, \"\\n\");\n", " window.jyp_print = jyp_print(cell, \"\");\n", "\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " Processing.logger.println = jyp_print(cell, \"\\n\");\n", " Processing.logger.print = jyp_print(cell, \"\");\n", " });\n", "\n", "\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " Sketch #1:
\n", "
\n", "
\n", "
\n", " \n", " \n", " \n", " \n", "
\n", "Sketch #1 state: Loading...
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "size(400, 300);\n", "\n", "fill(255);\n", "stroke(0);\n", "ellipse(200, 100, 0.5 * 100, 0.5 * 100);\n", "// body:\n", "line(200, 100, 200, 100 + 0.5 * 100);\n", "// arms:\n", "line(200 - 0.5 * 50, 100 + 0.5 * 60, \n", " 200 + 0.5 * 50, 100 + 0.5 * 60);\n", "// Shadow:\n", "fill(180);\n", "noStroke();\n", "ellipse(200, 100 + 0.5 * 100, 0.5 * 30, 0.5 * 10);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Consider the problem of drawing a stick person at some location x,y at a particular scale.\n", "\n", "Let's say, at location (200, 100) at scale 1.0." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.4 With Variables" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "application/javascript": [ "\n", " var component = document.getElementById(\"sketch_25\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"state_25\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"controls_div_25\");\n", " if (component != undefined)\n", " component.remove();\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " // FIXME: Stop all previously running versions (?)\n", " var processingInstance = Processing.getInstanceById(\"canvas_25\");\n", " if (processingInstance != undefined && processingInstance.isRunning())\n", " processingInstance.noLoop();\n", " });\n", "\n", "\n", " var output_area = this;\n", " // find my cell element\n", " var cell_element = output_area.element.parents('.cell');\n", " // which cell is it?\n", " var cell_idx = Jupyter.notebook.get_cell_elements().index(cell_element);\n", " // get the cell object\n", " var cell = Jupyter.notebook.get_cell(cell_idx);\n", "\n", " function jyp_print(cell, newline) {\n", " return function(message) {\n", " cell.get_callbacks().iopub.output({header: {\"msg_type\": \"stream\"},\n", " content: {text: message + newline,\n", " name: \"stdout\"}});\n", " }\n", " }\n", " window.jyp_println = jyp_print(cell, \"\\n\");\n", " window.jyp_print = jyp_print(cell, \"\");\n", "\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " Processing.logger.println = jyp_print(cell, \"\\n\");\n", " Processing.logger.print = jyp_print(cell, \"\");\n", " });\n", "\n", "\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " Sketch #25:
\n", "
\n", "
\n", "
\n", " \n", " \n", " \n", " \n", "
\n", "Sketch #25 state: Loading...
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "size(400, 300);\n", "\n", "// scale is a value indicating the size of stick person\n", "float scale = 0.75;\n", "// x,y are values indicating the location of stick person\n", "int x = 300;\n", "int y = 100;\n", "int bodyLength = 100;\n", "\n", "fill(255);\n", "stroke(0);\n", "ellipse(x, y, scale * 100, scale * bodyLength);\n", "// base of body:\n", "float baseX = x;\n", "float baseY = y + scale * bodyLength;\n", "// body:\n", "line(x, y, baseX, baseY);\n", "// arms:\n", "line(x - scale * 50, y + scale * 60, \n", " x + scale * 50, y + scale * 60);\n", "// Shadow:\n", "fill(180);\n", "noStroke();\n", "ellipse(baseX, baseY, scale * 30, scale * 10);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.5 Smaller with Scale" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "application/javascript": [ "\n", " var component = document.getElementById(\"sketch_26\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"state_26\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"controls_div_26\");\n", " if (component != undefined)\n", " component.remove();\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " // FIXME: Stop all previously running versions (?)\n", " var processingInstance = Processing.getInstanceById(\"canvas_26\");\n", " if (processingInstance != undefined && processingInstance.isRunning())\n", " processingInstance.noLoop();\n", " });\n", "\n", "\n", " var output_area = this;\n", " // find my cell element\n", " var cell_element = output_area.element.parents('.cell');\n", " // which cell is it?\n", " var cell_idx = Jupyter.notebook.get_cell_elements().index(cell_element);\n", " // get the cell object\n", " var cell = Jupyter.notebook.get_cell(cell_idx);\n", "\n", " function jyp_print(cell, newline) {\n", " return function(message) {\n", " cell.get_callbacks().iopub.output({header: {\"msg_type\": \"stream\"},\n", " content: {text: message + newline,\n", " name: \"stdout\"}});\n", " }\n", " }\n", " window.jyp_println = jyp_print(cell, \"\\n\");\n", " window.jyp_print = jyp_print(cell, \"\");\n", "\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " Processing.logger.println = jyp_print(cell, \"\\n\");\n", " Processing.logger.print = jyp_print(cell, \"\");\n", " });\n", "\n", "\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " Sketch #26:
\n", "
\n", "
\n", "
\n", " \n", " \n", " \n", " \n", "
\n", "Sketch #26 state: Loading...
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "size(400, 300);\n", "\n", "// scale is a value indicating the size of stick person\n", "float scale = 0.5;\n", "// x,y are values indicating the location of stick person\n", "int x = 200;\n", "int y = 100;\n", "\n", "fill(255);\n", "stroke(0);\n", "ellipse(x, y, scale * 100, scale * 100);\n", "// base of body:\n", "float baseX = x;\n", "float baseY = y + scale * 100;\n", "// body:\n", "line(x, y, baseX, baseY);\n", "// arms:\n", "line(x - scale * 50, y + scale * 60, \n", " x + scale * 50, y + scale * 60);\n", "// Shadow:\n", "fill(180);\n", "noStroke();\n", "ellipse(baseX, baseY, scale * 30, scale * 10);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Two Stick People\n", "\n", "**NOTE**: in copy, don't declare the variables again, just assign them" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "application/javascript": [ "\n", " var component = document.getElementById(\"sketch_27\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"state_27\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"controls_div_27\");\n", " if (component != undefined)\n", " component.remove();\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " // FIXME: Stop all previously running versions (?)\n", " var processingInstance = Processing.getInstanceById(\"canvas_27\");\n", " if (processingInstance != undefined && processingInstance.isRunning())\n", " processingInstance.noLoop();\n", " });\n", "\n", "\n", " var output_area = this;\n", " // find my cell element\n", " var cell_element = output_area.element.parents('.cell');\n", " // which cell is it?\n", " var cell_idx = Jupyter.notebook.get_cell_elements().index(cell_element);\n", " // get the cell object\n", " var cell = Jupyter.notebook.get_cell(cell_idx);\n", "\n", " function jyp_print(cell, newline) {\n", " return function(message) {\n", " cell.get_callbacks().iopub.output({header: {\"msg_type\": \"stream\"},\n", " content: {text: message + newline,\n", " name: \"stdout\"}});\n", " }\n", " }\n", " window.jyp_println = jyp_print(cell, \"\\n\");\n", " window.jyp_print = jyp_print(cell, \"\");\n", "\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " Processing.logger.println = jyp_print(cell, \"\\n\");\n", " Processing.logger.print = jyp_print(cell, \"\");\n", " });\n", "\n", "\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " Sketch #27:
\n", "
\n", "
\n", "
\n", " \n", " \n", " \n", " \n", "
\n", "Sketch #27 state: Loading...
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "size(400, 300);\n", "\n", "// DRAW ONE!\n", "\n", "// scale is a value indicating the size of stick person\n", "float scale = 0.25;\n", "// x,y are values indicating the location of stick person\n", "int x = 100;\n", "int y = 50;\n", "\n", "fill(255);\n", "stroke(0);\n", "ellipse(x, y, scale * 100, scale * 100);\n", "// base of body:\n", "float baseX = x;\n", "float baseY = y + scale * 100;\n", "// body:\n", "line(x, y, baseX, baseY);\n", "// arms:\n", "line(x - scale * 50, y + scale * 60, \n", " x + scale * 50, y + scale * 60);\n", "// Shadow:\n", "fill(180);\n", "noStroke();\n", "ellipse(baseX, baseY, scale * 30, scale * 10);\n", "\n", "// REPEAT!\n", "\n", "// scale is a value indicating the size of stick person\n", "scale = 1.0;\n", "// x,y are values indicating the location of stick person\n", "x = 200;\n", "y = 100;\n", "\n", "fill(255);\n", "stroke(0);\n", "ellipse(x, y, scale * 100, scale * 100);\n", "// base of body:\n", "baseX = x;\n", "baseY = y + scale * 100;\n", "// body:\n", "line(x, y, baseX, baseY);\n", "// arms:\n", "line(x - scale * 50, y + scale * 60, \n", " x + scale * 50, y + scale * 60);\n", "// Shadow:\n", "fill(180);\n", "noStroke();\n", "ellipse(baseX, baseY, scale * 30, scale * 10);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.6 Setup and Draw" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "New way of creating sketches.\n", "\n", "Break code up into two functions:\n", "\n", "* setup() - all of the code that you want to run just once\n", "* draw() - the rest of your code" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "application/javascript": [ "\n", " var component = document.getElementById(\"sketch_28\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"state_28\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"controls_div_28\");\n", " if (component != undefined)\n", " component.remove();\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " // FIXME: Stop all previously running versions (?)\n", " var processingInstance = Processing.getInstanceById(\"canvas_28\");\n", " if (processingInstance != undefined && processingInstance.isRunning())\n", " processingInstance.noLoop();\n", " });\n", "\n", "\n", " var output_area = this;\n", " // find my cell element\n", " var cell_element = output_area.element.parents('.cell');\n", " // which cell is it?\n", " var cell_idx = Jupyter.notebook.get_cell_elements().index(cell_element);\n", " // get the cell object\n", " var cell = Jupyter.notebook.get_cell(cell_idx);\n", "\n", " function jyp_print(cell, newline) {\n", " return function(message) {\n", " cell.get_callbacks().iopub.output({header: {\"msg_type\": \"stream\"},\n", " content: {text: message + newline,\n", " name: \"stdout\"}});\n", " }\n", " }\n", " window.jyp_println = jyp_print(cell, \"\\n\");\n", " window.jyp_print = jyp_print(cell, \"\");\n", "\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " Processing.logger.println = jyp_print(cell, \"\\n\");\n", " Processing.logger.print = jyp_print(cell, \"\");\n", " });\n", "\n", "\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " Sketch #28:
\n", "
\n", "
\n", "
\n", " \n", " \n", " \n", " \n", "
\n", "Sketch #28 state: Loading...
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "void setup() {\n", " \n", "}\n", "\n", "void draw() {\n", "\n", "}" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "application/javascript": [ "\n", " var component = document.getElementById(\"sketch_29\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"state_29\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"controls_div_29\");\n", " if (component != undefined)\n", " component.remove();\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " // FIXME: Stop all previously running versions (?)\n", " var processingInstance = Processing.getInstanceById(\"canvas_29\");\n", " if (processingInstance != undefined && processingInstance.isRunning())\n", " processingInstance.noLoop();\n", " });\n", "\n", "\n", " var output_area = this;\n", " // find my cell element\n", " var cell_element = output_area.element.parents('.cell');\n", " // which cell is it?\n", " var cell_idx = Jupyter.notebook.get_cell_elements().index(cell_element);\n", " // get the cell object\n", " var cell = Jupyter.notebook.get_cell(cell_idx);\n", "\n", " function jyp_print(cell, newline) {\n", " return function(message) {\n", " cell.get_callbacks().iopub.output({header: {\"msg_type\": \"stream\"},\n", " content: {text: message + newline,\n", " name: \"stdout\"}});\n", " }\n", " }\n", " window.jyp_println = jyp_print(cell, \"\\n\");\n", " window.jyp_print = jyp_print(cell, \"\");\n", "\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " Processing.logger.println = jyp_print(cell, \"\\n\");\n", " Processing.logger.print = jyp_print(cell, \"\");\n", " });\n", "\n", "\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " Sketch #29:
\n", "
\n", "
\n", "
\n", " \n", " \n", " \n", " \n", "
\n", "Sketch #29 state: Loading...
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "void setup() {\n", " size(400, 100);\n", "}\n", "\n", "void draw() {\n", " // scale is a value indicating the size of stick person\n", " float scale = 0.25;\n", " // x,y are values indicating the location of stick person\n", " int x = 100;\n", " int y = 50;\n", "\n", " fill(255);\n", " stroke(0);\n", " ellipse(x, y, scale * 100, scale * 100);\n", " // base of body:\n", " float baseX = x;\n", " float baseY = y + scale * 100;\n", " // body:\n", " line(x, y, baseX, baseY);\n", " // arms:\n", " line(x - scale * 50, y + scale * 60, \n", " x + scale * 50, y + scale * 60);\n", " // Shadow:\n", " fill(180);\n", " noStroke();\n", " ellipse(baseX, baseY, scale * 30, scale * 10); \n", "}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Defining Functions with Parameters\n", "\n", "1. Take the code with variables\n", "2. define a new function, using void as TYPE\n", "3. put old code in new function, and indent\n", "3. move variables to parameters\n", "4. call the function where code was\n", "\n", "In class, we will transform the following to create a new function, stickPerson(x, y, scale)." ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [ { "data": { "application/javascript": [ "\n", " var component = document.getElementById(\"sketch_34\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"state_34\");\n", " if (component != undefined)\n", " component.remove();\n", " component = document.getElementById(\"controls_div_34\");\n", " if (component != undefined)\n", " component.remove();\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " // FIXME: Stop all previously running versions (?)\n", " var processingInstance = Processing.getInstanceById(\"canvas_34\");\n", " if (processingInstance != undefined && processingInstance.isRunning())\n", " processingInstance.noLoop();\n", " });\n", "\n", "\n", " var output_area = this;\n", " // find my cell element\n", " var cell_element = output_area.element.parents('.cell');\n", " // which cell is it?\n", " var cell_idx = Jupyter.notebook.get_cell_elements().index(cell_element);\n", " // get the cell object\n", " var cell = Jupyter.notebook.get_cell(cell_idx);\n", "\n", " function jyp_print(cell, newline) {\n", " return function(message) {\n", " cell.get_callbacks().iopub.output({header: {\"msg_type\": \"stream\"},\n", " content: {text: message + newline,\n", " name: \"stdout\"}});\n", " }\n", " }\n", " window.jyp_println = jyp_print(cell, \"\\n\");\n", " window.jyp_print = jyp_print(cell, \"\");\n", "\n", " require([window.location.protocol + \"//calysto.github.io/javascripts/processing/processing.js\"], function() {\n", " Processing.logger.println = jyp_print(cell, \"\\n\");\n", " Processing.logger.print = jyp_print(cell, \"\");\n", " });\n", "\n", "\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "
\n", " Sketch #34:
\n", "
\n", "
\n", "
\n", " \n", " \n", " \n", " \n", "
\n", "Sketch #34 state: Loading...
\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "void setup() {\n", " size(400, 100);\n", "}\n", "\n", "void drawStickPerson(int x, int y, float scale) {\n", " // scale is a value indicating the size of stick person\n", " //float scale = 0.25;\n", " // x,y are values indicating the location of stick person\n", " //int x = 100;\n", " //int y = 50;\n", "\n", " fill(255);\n", " stroke(0);\n", " ellipse(x, y, scale * 100, scale * 100);\n", " // base of body:\n", " float baseX = x;\n", " float baseY = y + scale * 100;\n", " // body:\n", " line(x, y, baseX, baseY);\n", " // arms:\n", " line(x - scale * 50, y + scale * 60, \n", " x + scale * 50, y + scale * 60);\n", " // Shadow:\n", " fill(180);\n", " noStroke();\n", " ellipse(baseX, baseY, scale * 30, scale * 10); \n", "}\n", "\n", "void draw() {\n", " fill(200, 229, 255);\n", " rect(0, 0, 400, 50); // sky\n", " fill(0, 255, 0);\n", " rect(0, 50, 400, 50); // ground\n", " drawStickPerson(100, 50, 0.25);\n", " drawStickPerson(200, 55, 0.5);\n", "}" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Calysto Processing", "language": "java", "name": "calysto_processing" }, "language_info": { "codemirror_mode": { "name": "text/x-java", "version": 2 }, "file_extension": ".java", "mimetype": "text/x-java", "name": "java" } }, "nbformat": 4, "nbformat_minor": 2 }